﻿using System;
using System.Web.UI;

public partial class Controls_FrontEnd_ImageLibrary : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var data = new Business.ImageLibrary().ImageLibrary_GetByCondition("[Default]=1");
        rptData.DataSource = data;
        rptData.DataBind();
    }

    public string ReWriteHtml(object obj)
    {
        return ConvertUnicode(obj.ToString());
    }

    private static String ConvertUnicode(String sContent)
    {
        sContent = sContent.Trim().ToLower();
        const string sUtf8Lower = "a|á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ|đ|e|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|i|í|ì|ỉ|ĩ|ị|o|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|u|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|y|ý|ỳ|ỷ|ỹ|ỵ";

        const string sUcs2Lower = "a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|d|e|e|e|e|e|e|e|e|e|e|e|e|i|i|i|i|i|i|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|u|u|u|u|u|u|u|u|u|u|u|u|y|y|y|y|y|y";

        var aUtf8Lower = sUtf8Lower.Split(new[] { '|' });

        var aUcs2Lower = sUcs2Lower.Split(new[] { '|' });

        var l = aUtf8Lower.GetUpperBound(0);

        for (var i = 1; i < l; i++)
            sContent = sContent.Replace(aUtf8Lower[i], aUcs2Lower[i]);
        sContent = sContent.Replace(" - ", " ");
        sContent = sContent.Replace(" ", "-");

        const string filter = "-0123456789abcdefghijklmnopqrstuvwxyz";
        var s = "";
        l = sContent.Length;
        for (var i = 0; i < l; i++)
        {
            if (filter.IndexOf(sContent[i]) >= 0)
            {
                s = s + sContent[i];
            }
        }

        return s;
    }
}